package service

import (
	"monthly-test/global"
	"monthly-test/internal/model/dao"
	"monthly-test/internal/request"
)

func CheckUserByAccount(account string) (dao.User, error) {
	var user dao.User
	err := global.DB.Where("account = ?", account).First(&user).Error
	if err != nil {
		return dao.User{}, err
	}
	return user, nil
}

func UpdateUser(req request.UpdateReq) error {
	u := dao.User{
		Image: req.Image,
		Name:  req.Name,
		Sign:  req.Sign,
	}
	err := global.DB.Model(&u).Where("account = ?", req.Account).Updates(&u).Error
	if err != nil {
		return err
	}
	return nil
}
func FriendList(userId int) ([]dao.Friend, error) {
	var friends []dao.Friend
	err := global.DB.Where("user_id = ?", userId).Order("name DESC").Find(&friends).Error
	if err != nil {
		return []dao.Friend{}, err
	}
	return friends, nil
}
